import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Logger,
} from '@nestjs/common';
import { ProductService } from './product.service';
import { CreateProductDto } from './dto/create-product.dto';
import { UpdateProductDto } from './dto/update-product.dto';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { Product } from 'src/schemas/product.schema';
import { Record } from 'src/schemas/record.schema';

const logger = new Logger('product.controller');

@Controller('product')
@ApiTags('产品模块')
export class ProductController {
  constructor(private readonly productService: ProductService) {}

  @Post()
  @ApiOperation({
    summary: '增加一个产品',
  })
  create(@Body() createProductDto: Product) {
    return this.productService.create(createProductDto);
  }

  @Get()
  @ApiOperation({
    summary: '获取全部库存',
  })
  findAll() {
    return this.productService.findAll();
  }

  @Get('category')
  @ApiOperation({
    summary: '获取手机分类',
  })
  findCategory() {
    return this.productService.findCategory();
  }

  @Get('item/:id')
  findOne(@Param('id') id: string) {
    return this.productService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({
    summary: '出库',
  })
  update(@Param('id') id: string, @Body() record: Record) {
    return this.productService.update(id, record);
  }

  @Delete(':id')
  @ApiOperation({
    summary: '删除所有同类条目',
  })
  remove(@Param('id') id: string) {
    return this.productService.remove(id);
  }

  @Patch('imei/:id')
  @ApiOperation({
    summary: '删除指定imei',
  })
  removeIMEI(
    @Param('id') id: string,
    @Body() updateProductDto: UpdateProductDto,
  ) {
    return this.productService.removeIMEI(id, updateProductDto);
  }
}
